package com.xiashitech.agent.instrumentation.dubbo;

import cn.hutool.core.date.DateUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.alibaba.dubbo.remoting.exchange.Request;
import com.alibaba.dubbo.remoting.exchange.Response;
import com.alibaba.dubbo.rpc.RpcInvocation;
import com.alibaba.dubbo.rpc.RpcResult;
import com.alibaba.dubbo.rpc.protocol.dubbo.DecodeableRpcInvocation;
import com.xiashitech.agent.config.StartConfig;
import com.xiashitech.agent.dto.UserRequest;
import com.xiashitech.agent.instrumentation.base.AbstractAttributesExtractor;
import com.xiashitech.agent.instrumentation.base.context.TraceContextVars;
import com.xiashitech.agent.instrumentation.base.context.XSBaggage;
import com.xiashitech.agent.instrumentation.base.context.XSContext;
import com.xiashitech.agent.instrumentation.bridge.Java8Bridge;
import com.xiashitech.agent.instrumentation.dubbo.common.inst.DubboRequest;
import com.xiashitech.agent.instrumentation.spring.controller.apicapture.utils.ApiSyncUtil;
import com.xiashitech.agent.instrumentation.utils.BaggageUtil;
import com.xiashitech.agent.instrumentation.utils.MachineAttributesUtil;
import com.xiashitech.agent.utils.JsonUtil;
import com.xiashitech.agent.utils.ObjectFieldUtil;
import com.xiashitech.interfaces.agent.dto.SystemInfoDTO;
import com.xiashitech.interfaces.agent.dto.api.DesenseParam;
import io.opentelemetry.javaagent.bootstrap.internal.InstrumentationConfig;
import io.opentelemetry.javaagent.shaded.io.opentelemetry.api.baggage.Baggage;
import io.opentelemetry.javaagent.shaded.io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.javaagent.shaded.io.opentelemetry.api.trace.Span;
import io.opentelemetry.javaagent.shaded.io.opentelemetry.context.Context;
import org.jetbrains.annotations.Nullable;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;

import static java.lang.Integer.parseInt;


public class XSDubboLt27Handler extends AbstractAttributesExtractor<UserRequest, Void> {
    public String getAttributesExtractorName() {
        return XSDubboLt27Handler.class.getName();
    }

    public static Optional init(UserRequest userRequest, Object request) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
        System.out.println("###debug003 init  tradeId " + Span.current().getSpanContext().getTraceId());
        System.out.println("###debug003 init  userRequest " + userRequest.toString());
        System.out.println("###debug003 init  userRequest " + userRequest.toString());
        XSContext xsContext = Java8Bridge.currentForXSContext();
        System.out.println("###debug003 init  Java8Bridge xsContext " + xsContext.toString());
        System.out.println("###Thread init ID:" + Thread.currentThread().getId() + "Thread Name:" + Thread.currentThread().getName());
        try {
            Baggage baggage = Baggage.current();
            System.out.println("###debug003-0 current baggage " + baggage.toString());
            System.out.println("###debug003-0-1 userId " + baggage.getEntryValue("xs.userId"));
            System.out.println("###debug003-0-2 endpoint-api " + baggage.getEntryValue("endpoint-api"));
            /* ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
            if(attributes!=null) {
                System.out.println("###debug000 get  url start:");
                HttpServletRequest httpRequest = attributes.getRequest();
                String url = httpRequest.getRequestURI()+"?"+httpRequest.getQueryString();
                System.out.println("###debug000 get current url:"+url);
            }*/
            System.out.println("###debug003-0-0 request " + request.toString());
            Object data = ((Request) request).getData();
            Object args[] = null;
            JSONObject userJsonObject = new JSONObject();
            String endPointApiName = "";
            String service = "";
            String userId = "";
            String method = "";
            if (data instanceof DecodeableRpcInvocation) {
                args = ((DecodeableRpcInvocation) data).getArguments();
                String requestPath = ((DecodeableRpcInvocation) data).getAttachment("path");
                service = requestPath.substring(requestPath.lastIndexOf(".") + 1);
                method = ((DecodeableRpcInvocation) data).getMethodName();
                if (service.equals("Agent")) {
                    endPointApiName = "dubbo.haier." + args[0].toString().substring(args[0].toString().lastIndexOf(".") + 1).replace(":", ".");
                } else {
                    endPointApiName = "dubbo.haier." + service + "." + method;
                }
                System.out.println("###debug003-6-1 endPointApiName  " + endPointApiName);
                Object baggageDubbo = ((DecodeableRpcInvocation) data).getAttachment("baggage");

                if (baggageDubbo != null) {
                  /*  JSONObject baggageObj = JSONUtil.parseObj(baggageDubbo);
                    System.out.println("###debug003-0-1 baggageObj  " + baggageObj);
                    userId = String.valueOf(baggageObj.get("xs.userId"));
                    System.out.println("###debug003-0-1 userId  " + userId);*/
                    System.out.println("###debug003-6-1-1 baggageDubbo  " + baggageDubbo.toString());
                }

            } else if (data instanceof RpcInvocation) {
                args = ((RpcInvocation) data).getArguments();
                String requestPath = ((RpcInvocation) data).getAttachment("path");
                service = requestPath.substring(requestPath.lastIndexOf(".") + 1);
                method = ((RpcInvocation) data).getMethodName();
                if (service.equals("Agent")) {
                    endPointApiName = "dubbo.haier." + args[0].toString().substring(args[0].toString().lastIndexOf(".") + 1).replace(":", ".");
                } else {
                    endPointApiName = "dubbo.haier." + service + "." + method;
                }
                System.out.println("###debug003-6-2 service.method " + service + "." + method);
                Object baggageDubbo = ((RpcInvocation) data).getAttachment("baggage");

                if (baggageDubbo != null) {
                    System.out.println("###debug003-6-2-1 baggageDubbo  " + baggageDubbo.toString());
                  /*  JSONObject baggageObj = JSONUtil.parseObj(baggageDubbo);
                    System.out.println("###debug003-6-2-1 baggageObj  " + baggageObj);
                    userId = String.valueOf(baggageObj.get("xs.userId"));
                    System.out.println("###debug003-6-2-1 userId  " + userId);*/
                }
            }
           // System.out.println("###debug003-1 ars[0]" + args[0].toString());

            if (baggage.getEntryValue("xs.userId") != null && baggage.getEntryValue("xs.userId").length() != 0) {
                userId = baggage.getEntryValue("xs.userId").replace("session_user_id(java.lang.Integer):%20", "").trim();
                userId = userId.replace("session_user_id(java.lang.Integer):", "").trim();
                System.out.println("###debug003-1-2-2-0 userId:" + userId);
            } else if (userRequest.getUserid() != null && !userRequest.getUserid().equals("")) {
                userId = userRequest.getUserid().replace("session_user_id(java.lang.Integer):%20", "").trim();
                userId = userId.replace("session_user_id(java.lang.Integer):", "").trim();
            }

            if (args.length > 1) {
                System.out.println("###debug003-1-2-0 args[0]" + args[0].toString());
                System.out.println("###debug003-1-2-1 args[1]" + args[1].toString());
                   /* String requestServiceMethod = args[0].toString().substring(args[0].toString().lastIndexOf(".") + 1).replace(":", ".");
                    endPointApiName = "dubbo.haier." + requestServiceMethod;
                    System.out.println("###debug003-1-2-2 endPointApiName:" + endPointApiName);*/
                JSONObject userArgsJsonObject = JSONUtil.parseObj(args[1]);
                Object user = userArgsJsonObject.get("baseUser");
                // System.out.println("###debug003-1-2-3 get baseUser user" + user.toString());
                userJsonObject = JSONUtil.parseObj(user);
                if(userJsonObject==null || userJsonObject.size()==0)
                {
                    userId = userArgsJsonObject.getStr("id");
                }
                else
                {
                    userId = String.valueOf(userJsonObject.get("id"));
                }
                System.out.println("###debug003-1-2-2-1 userId:" + userId);
            } else if (args.length == 1) {
                System.out.println("###debug003-1-2" + JsonUtil.convertObjectToString(args));
                if (method.equals("findUserById")) {
                    userId = args[0].toString();
                    System.out.println("###debug003-1-2 findUserById userId" + userId);
                } else {
                    userJsonObject = JSONUtil.parseObj(args[0]);
                    userId = String.valueOf(userJsonObject.get("id"));
                }

                System.out.println("###debug003-1-2-0 userId:" + userId);

            } else {
                System.out.println("###debug003-1-3" + args.toString());
                return Optional.ofNullable(null);
            }


            System.out.println("###debug003-2 userJsonObject" + userJsonObject.toString() + "userId: " + userId);
           /* Optional userIdOptional = Optional.ofNullable(userJsonObject.get("id"));
            System.out.println("###debug003-3");*/
            userRequest.setEndpointApi(endPointApiName);
          /*  if (userId==null || userId.equals("")) {
                userRequest.setUserid(baggage.getEntryValue("xs.userId"));
            } else {
                userRequest.setUserid(userId);
            }*/
            userRequest.setRequestDate(DateUtil.dateSecond().toString());
          /*  if (!userIdOptional.isPresent()) {
                System.out.println("###debug003-4");
                return userIdOptional;
            }*/
            System.out.println("###debug003-5 userId:" + userId + " endPointApiName:" + endPointApiName);
            userRequest.setApiSystemId(StartConfig.getParamValueFromKey(StartConfig.systemId));
            userRequest.setIsOutApi(true);
           // userId = "2";
            TraceContextVars.get()
                    .set("xs.userId", userId == null ? baggage.getEntryValue("xs.userId") : userId)
                    .set("xs.api.path", service + "." + method)
                    .set("xs.api.requestParams", args.toString())
                    .set("xs.loginName", userRequest.getLoginName() == null ? "" : userRequest.getLoginName())
                    .set("xs.sessionId", userRequest.getSessionId() == null ? "" : userRequest.getSessionId())
                    .set("xs.requestDate", userRequest.getRequestDate() == null ? "" : userRequest.getRequestDate().toString())
                    .set("xs.sessionUpdate", userRequest.getSessionUpdate() == null ? "false" : userRequest.getSessionUpdate().toString())
                    .set("endpoint-api", userRequest.getEndpointApi())
                    .set("api-systemId", userRequest.getApiSystemId());
//            Baggage baggage2 = Baggage.current();
//            System.out.println("###debug003-6 current baggage " + baggage2.toString());
//            System.out.println("###debug003-6-1 userId " + baggage2.getEntryValue("xs.userId"));
//            System.out.println("###debug003-6-2 endpoint-api " + baggage2.getEntryValue("endpoint-api"));

        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("###debug003-5-1" + e.toString());
        }

        return Optional.ofNullable(request);
    }

    @Override
    public void onXSStart(AttributesBuilder attributesBuilder, Context context, UserRequest userRequest) {
    }

    // public class ServerHandler  extends ReplayingDecoder {
    public static Object handle(UserRequest userRequest, Object response) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
        System.out.println("###debug004 handle traceid:" + Span.current().getSpanContext().getTraceId());
        //SessionUtil.syncBaggage();
        Baggage baggage = Baggage.current();
        userRequest.setIsOutApi(true);
        if (response instanceof Response) {

            if (userRequest != null) {
                try {
                  /*  Baggage.current().toBuilder()
                            .put("xs.sessionUpdate", userRequest.getSessionUpdate() == null ? "false" : userRequest.getSessionUpdate().toString())
                            .build().makeCurrent();*/
                    Object data = ((Response) response).getResult();
                    if (data == null) {
                        return response;
                    }
                    Object resultResponse = ((RpcResult) data).getValue();
                    String apiRecordSizeRuleStr = "1_1";
                    String[] apiRecordSizeRuleS = apiRecordSizeRuleStr.split("_");
                    int apiListdeep = parseInt(apiRecordSizeRuleS[0]);
                    int apiListindex = parseInt(apiRecordSizeRuleS[1]);
                    int apiRecordSize = ObjectFieldUtil.getRecordSize(resultResponse, 20, 1, 0);
                    TraceContextVars.get()
                            .set("xs.api.records.size", String.valueOf(apiRecordSize));
                    String jsonResult = JsonUtil.convertObjectToString(((RpcResult) data).getValue());
                    System.out.println("###debug004-1 handle jsonResult data getValue " + jsonResult + " recordSize " + apiRecordSize);
                    //  String contentType = (String)jsonResult.getClass().getMethod("getContentType").invoke(jsonResult);
                    String contentType = "json";
                    if (contentType != null && contentType.contains("json")) {
                        /**
                         * 根据数据访问权限及配置项对api返回值进行脱敏
                         */

                        if (userRequest.getIsOutApi()) {
                            String charset = InstrumentationConfig.get().getString("xs.charset.textcontent");
                            String jsonString = null;
                            if (jsonResult.length() > 0) {
                                if (charset != null) {
                                    jsonString = new String(jsonResult.getBytes(), charset);
                                } else {
                                    jsonString = new String(jsonResult.getBytes());
                                }
                            }
                            System.out.println("###debug004-2 handle jsonString " + jsonString);
                            /**
                             * 获取api的返回值的key列表
                             */
                            if (jsonString != null) {
                                Set<String> jsonKeySet = new HashSet();
                                JsonUtil.getJsonKeys(jsonString, jsonKeySet);
                                String endpointApi = userRequest.getEndpointApi();
                                if (endpointApi != null) {
                                    endpointApi = endpointApi.replace("/", "_");
                                }
                                //System.out.println("###debug004-2 handle endpointApi " + endpointApi);

                                DesenseParam desenseParam = DesenseParam.builder().apiName(endpointApi).system(userRequest.getApiSystemId()).desenseParam(new ArrayList(jsonKeySet)).build();
                                ApiSyncUtil.syncApiDesense(desenseParam);
                            }

                            XSBaggage[] baggagesWithCurrentAndConfluence = XSBaggage.currentWithConfluence();
                            for (XSBaggage xsBaggage : baggagesWithCurrentAndConfluence) {
                                if (xsBaggage != null) {
                                    String endpointApiBack = xsBaggage.getEntryValue("endpoint-api-back");
                                    if (jsonString != null && endpointApiBack != null) {
                                        String[] endpointApiBacks = endpointApiBack.split("#");
                                        for (String endpointApiBackItem : endpointApiBacks) {
                                            String jsonPath = jsonString;
                                            //jsonPath = "{\"result\":{\"success\":true,\"result\":{\"supplierInfo\":{\"user\":{\"id\":26039,\"name\":\"????\",\"type\":2,\"roles\":[],\"tags\":\"??????,??\",\"mobile\":\"13804285311\",\"nick\":\"????\",\"encryptedPassword\":\"2b4a@42d2bb32e05e70198617\",\"phone\":\"87329506\",\"email\":\"haoping@dnpc-dalian.com\",\"roleStr\":\"SUPPLIER\",\"status\":0,\"approveStatus\":3,\"enterPassAt\":1423855071000,\"accountType\":1,\"origin\":0,\"refuseStatus\":0,\"qualifyStatus\":-1,\"step\":5,\"stepAt\":1427823543000,\"token\":\"2603920220725125940\",\"userToken\":\"SESSION_f599591d7a5f11cbcaf5819417065f9b\",\"lastSubmitApprovalAt\":1440007295000,\"lastLoginAt\":1659536396000,\"createdAt\":1423255479000,\"updatedAt\":1657739551000,\"typeEnum\":\"SELLER\"},\"company\":{\"id\":8201,\"userId\":26039,\"isComplete\":1,\"completeAt\":1424030062000,\"productLine\":\"?? ?????? ????? ????? ??? ???? ???? ?? ??? ???? ??? ??\",\"corporation\":\"????????????\",\"corporationEn\":\"DALIAN NITTO PLASTIC MOLDING CO.,LTD\",\"corporationClear\":\"????????????\",\"supplierCode\":\"V14121\",\"actingBrand\":\"\",\"corpAddr\":\"?????IC-21\",\"zipcode\":\"116600\",\"groupName\":\"DALIAN NITTO PLASTIC MOLDING CO.,LTD\",\"groupAddr\":\"?????IC-21\",\"initAgent\":\"???\",\"fixedAssets\":2550000000,\"faCoinType\":1,\"regCapital\":5300000000,\"rcCoinType\":1,\"regCountry\":1,\"regProvince\":210000,\"regCity\":210200,\"worldTop\":0,\"officialWebsite\":\"http://www.dnpc-dalian.com/\",\"personScale\":3,\"foundAt\":854690400000,\"desc\":\"??????1997??2010?????????????????????????2011??????????????????ISO9001?ISO14001?UL???TS16949?????????????????????????????????????20t~1600t????44?,?????????,HEAT&COOL???????????????,???????????,???????????????????????????????????????20????????????????????????????????????????????????????????????????????????????????????\",\"nature\":5,\"listedStatus\":0,\"listedRegion\":\"\",\"ticker\":\"\",\"businessLicense\":\"http://wj.ihaier.com:8081/newImages/2019/10/09/26039_1570585850012_2d17dbbcfb72400d2131c927969e9183.jpg\",\"businessLicenseId\":\"91210242604888856Q\",\"blDate\":2432440800000,\"orgCert\":\"http://wj.ihaier.com:8081/newImages/2019/10/09/26039_1570585856967_2d17dbbcfb72400d2131c927969e9183.jpg\",\"orgCertId\":\"91210242604888856Q\",\"ocDate\":2432440800000,\"taxNo\":\"http://wj.ihaier.com:8081/newImages/2019/10/09/26039_1570585861878_2d17dbbcfb72400d2131c927969e9183.jpg\",\"taxNoId\":\"91210242604888856Q\",\"participateCount\":4137,\"customers\":\"{\\\"appliance\\\":[{\\\"remark\\\":\\\"????\\\",\\\"percentage\\\":\\\"\\\",\\\"passivePercentage\\\":\\\"10\\\",\\\"customerFile\\\":\\\"\\\",\\\"category\\\":\\\"-1\\\"},{\\\"remark\\\":\\\"????\\\",\\\"percentage\\\":\\\"\\\",\\\"passivePercentage\\\":\\\"32\\\",\\\"customerFile\\\":\\\"\\\",\\\"category\\\":\\\"-1\\\"}],\\\"car\\\":[{\\\"remark\\\":\\\"????\\\",\\\"percentage\\\":\\\"\\\",\\\"passivePercentage\\\":\\\"33\\\",\\\"customerFile\\\":\\\"\\\"}],\\\"other\\\":[{\\\"remark\\\":\\\"?????\\\",\\\"percentage\\\":\\\"10\\\",\\\"passivePercentage\\\":\\\"10\\\",\\\"customerFile\\\":\\\"\\\"},{\\\"remark\\\":\\\"????\\\",\\\"percentage\\\":\\\"\\\",\\\"passivePercentage\\\":\\\"6\\\",\\\"customerFile\\\":\\\"\\\"},{\\\"remark\\\":\\\"????\\\",\\\"percentage\\\":\\\"\\\",\\\"passivePercentage\\\":\\\"4\\\",\\\"customerFile\\\":\\\"\\\"}]}\",\"factories\":\"[]\",\"facFileName\":\"\",\"facFileUrl\":\"\",\"createdAt\":1423255479000,\"updatedAt\":1570632692000,\"completeInfo\":true},\"companyMainBusinesses\":[{\"id\":290587,\"firstLevelId\":693,\"firstLevelName\":\"??\",\"secondLevelId\":695,\"secondLevelName\":\"????\",\"mainBusinessId\":697,\"name\":\"??????\",\"companyId\":8201,\"userId\":26039,\"createdAt\":1526665872000,\"updatedAt\":1526665872000},{\"id\":290589,\"firstLevelId\":693,\"firstLevelName\":\"??\",\"secondLevelId\":695,\"secondLevelName\":\"????\",\"mainBusinessId\":699,\"name\":\"??????\",\"companyId\":8201,\"userId\":26039,\"createdAt\":1526665872000,\"updatedAt\":1526665872000},{\"id\":290591,\"firstLevelId\":266,\"firstLevelName\":\"????\",\"secondLevelId\":290,\"secondLevelName\":\"?????\",\"mainBusinessId\":291,\"name\":\"?????\",\"companyId\":8201,\"userId\":26039,\"createdAt\":1526665872000,\"updatedAt\":1526665872000}],\"companySupplyParks\":[{\"id\":43833,\"companyId\":8201,\"userId\":26039,\"supplyParkId\":1,\"name\":\"??\",\"createdAt\":1424961560000,\"updatedAt\":1424961560000},{\"id\":43835,\"companyId\":8201,\"userId\":26039,\"supplyParkId\":4,\"name\":\"??\",\"createdAt\":1424961560000,\"updatedAt\":1424961560000},{\"id\":43837,\"companyId\":8201,\"userId\":26039,\"supplyParkId\":7,\"name\":\"??\",\"createdAt\":1424961560000,\"updatedAt\":1424961560000}]},\"oldValues\":{}}}}";
                                          //  jsonPath = "";
                                            String apiName = null;
                                            String[] desenseAction = endpointApiBackItem.split("&");
                                            for (int i = 0; i < desenseAction.length; i++) {
                                                if (i == 0) {
                                                    apiName = desenseAction[0];
                                                    if (!baggage.getEntryValue("endpoint-api").equals(apiName)) {
                                                        break;
                                                    } else {
                                                        continue;
                                                    }
                                                }
                                                String[] desenseActionItem = desenseAction[i].split("=");
                                                String patchPath = desenseActionItem[0];
                                                String[] patchPathItem = desenseActionItem[1].split(",");
                                                System.out.println("###debug004-3-1 handle patchPathItem " + patchPathItem);
                                                String isExecute = patchPathItem[0];
                                                String regular = patchPathItem[1];
                                                String replaceSymbol = patchPathItem[2];
                                                String systemId = patchPathItem[3];
                                                System.out.println("###debug004-3-1 handle StartConfig.systemId " + StartConfig.getParamValueFromKey(StartConfig.systemId) + "systemId " + systemId);
                                                System.out.println("###debug004-3-1 handle isExecute " + isExecute);
                                                System.out.println("###debug004-3-1-3 handle patchPath  " + patchPath);
                                                System.out.println("###debug004-3-1 handle regular  " + regular);
                                                System.out.println("###debug004-3-1 handle replaceSymbol " + replaceSymbol);
                                                //systemId = "haier-test";
                                                int deep = patchPath.split("/").length;
                                                String fieldName = patchPath.substring(patchPath.lastIndexOf("/") + 1);

                                                //执行脱敏
                                                if ("true".equals(isExecute) && StartConfig.getParamValueFromKey(StartConfig.systemId).equals(systemId)) {
                                                    System.out.println("###debug004-3-2 handle jsonString " + jsonString);
                                                    if (jsonString.length() > 0) {
                                                       // jsonPath = JsonUtil.jsonPatch(jsonPath, patchPath, regular, replaceSymbol);
                                                        ObjectFieldUtil.replaceObjectFieldValue(data, String.class, fieldName, regular, replaceSymbol, deep);
                                                        ((Response) response).setResult(data);
                                                        System.out.println("###debug004-6 resonpse:" + JsonUtil.convertObjectToString(response));
                                                    }

                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                } catch (Throwable e) {
                    e.printStackTrace();
                }
            }
            // MachineAttributesUtil.fillMachineAttributes(attributesBuilder);
        }
        System.out.println("###debug005 handle");

        return response;
    }

    public void onXSEnd(AttributesBuilder attributesBuilder, Context context, UserRequest userRequest, @Nullable Void unused, @Nullable Throwable throwable) {
        System.out.println("###dubbo onXSEnd TraceId:" + Span.current().getSpanContext().getTraceId());

        Baggage baggage = Baggage.current();
        attributesBuilder.put("xs.userId", baggage.getEntryValue("xs.userId") == null ? "" : baggage.getEntryValue("xs.userId"));
        attributesBuilder.put("xs.loginName", baggage.getEntryValue("xs.loginName") == null ? "" : baggage.getEntryValue("xs.loginName"));
        attributesBuilder.put("xs.sessionId", baggage.getEntryValue("xs.sessionId") == null ? "" : baggage.getEntryValue("xs.sessionId"));
        attributesBuilder.put("xs.requestDate", baggage.getEntryValue("xs.requestDate") == null ? "" : baggage.getEntryValue("xs.requestDate"));
        attributesBuilder.put("xs.sessionUpdate", baggage.getEntryValue("xs.sessionUpdate") == null ? "" : baggage.getEntryValue("xs.sessionUpdate"));
        attributesBuilder.put("xs.systemId", StartConfig.getParamValueFromKey(StartConfig.systemId));
        attributesBuilder.put("xs.systemReg", SystemInfoDTO.getConfig().getSystemExist());
        attributesBuilder.put("xs.sourceSystemId", baggage.getEntryValue("xsAuthSystemId") == null ? StartConfig.getParamValueFromKey(StartConfig.systemId) : baggage.getEntryValue("xsAuthSystemId"));

        attributesBuilder.put("xs.api.records.size", baggage.getEntryValue("xs.api.records.size"));

        MachineAttributesUtil.fillMachineAttributes(attributesBuilder);
    }


    public void onXSStart(AttributesBuilder attributesBuilder, Context context, DubboRequest dubboRequest) {

    }


}

